/**
 * User: Obi
 * Date: 02.08.11
 * Time: 21:27
 */
package com.jediflasher.game_client.controller {
import com.jediflasher.game_client.data.BaseData;
import com.jediflasher.game_client.events.server.ServerConnectorEvent;
import com.jediflasher.game_client.server.MessageWrapper;
import com.jediflasher.game_client.server.ServerConnector;
import com.jediflasher.game_client.server.messages.MessageType;
import com.jediflasher.game_client.view.BaseView;
import com.netease.protobuf.Message;

public class BaseController {

	public function BaseController(serverConnector:ServerConnector, model:BaseData, view:BaseView) {
		this._serverConnector = serverConnector;
		this._serverConnector.addEventListener(ServerConnectorEvent.MESSAGE_RECEIVED, this.handler_messageReceived);
		this._model = model;
		this._view = view;
	}

	/**
	 * @private
	 */
	private var _serverConnector:ServerConnector;

	/**
	 * @private
	 */
	protected var _model:BaseData;

	public function get data():BaseData {return this._model;}

	/**
	 * @private
	 */
	protected var _view:BaseView;

	public function get view():BaseView {return this._view;}

	public function send(messageType:int, serviceType:int, serviceMessageType:int, message:Message, requestId:int = 0):void {
		this._serverConnector.send(messageType, serviceType, serviceMessageType, message, requestId);
	}

	/**
	 * @private
	 */
	protected function receiveMessage(messageWrapper:MessageWrapper):void {}

	/**
	 * @private
	 */
	private function handler_messageReceived(event:ServerConnectorEvent):void {
		receiveMessage(event.messageWrapper);
	}


}
}
